import portService from "@/portService";
import { UserType } from "@/typings";
import { defineStore } from "pinia";
import { ref } from "vue";

const useUserStore = defineStore(
  "userStore",
  () => {
    const userInfo = ref<UserType>({
      token: "",
      name: "",
      avatar: "",
    });

    const getUserInfo = async () => {
      const { data } = await portService.loginApi();
      userInfo.value = data;
    };

    return {
      userInfo,
      getUserInfo,
    };
  },
  {
    persist: {
      enabled: true,

      strategies: [
        {
          storage: sessionStorage,
          paths: ["userInfo"],
        },
      ],
    },
  } as any
);

export default useUserStore;
